package com.example.design.filter.filter;


import com.example.design.filter.ScheduleFilter;
import com.example.design.filter.context.ScheduleContext;
import com.example.design.filter.context.ScheduleUser;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 上班5天后必须休息
 */
public class MustRestFilter implements ScheduleFilter {

    public static final ScheduleFilter instance = new MustRestFilter();

    @Override
    public void filter(ScheduleContext context) {
        List<ScheduleUser> restUsers = context.getScheduleUsers().parallelStream()
                .filter(user -> user.workDays(context.getScheduleDate()) >= 5)
                .collect(Collectors.toList());
        context.addRestUsers(restUsers);
    }

}
